<template>
  <div class="app-container">
    <header class="app-header">
      <h1>Vue + Electron 桌面应用</h1>
      <p class="subtitle">集成数据库功能的现代化桌面应用</p>
      
      <!-- 添加导航栏 -->
      <nav class="app-nav">
        <button 
          class="nav-btn" 
          :class="{ active: activeView === 'home' }"
          @click="activeView = 'home'"
        >
          首页
        </button>
        <button 
          class="nav-btn" 
          :class="{ active: activeView === 'database' }"
          @click="activeView = 'database'"
        >
          数据库测试
        </button>
      </nav>
    </header>

    <main class="app-content">
      <!-- 首页内容 -->
      <section v-if="activeView === 'home'" class="card electron-card">
        <h2>Electron 功能测试</h2>
        <div class="card-content">
          <p>点击下方按钮测试 Electron 主进程功能</p>
          <button class="primary-btn" @click="callElectronAPI">
            <span class="btn-icon">⚡</span>
            调用 Electron API
          </button>
          <div v-if="result" class="result-box">
            <h3>返回结果:</h3>
            <p>{{ result }}</p>
          </div>
        </div>
      </section>

      <!-- 数据库测试内容（通过组件显示） -->
      <DatabaseTest v-if="activeView === 'database'" />
    </main>
  </div>
</template>


<script>
import { ref } from 'vue';
import DatabaseTest from './components/DatabaseTest.vue';

export default {
  components: {
    DatabaseTest
  },
  setup() {
    const result = ref('');
    const isElectron = ref(!!window.electronAPI);
    const activeView = ref('home'); // 添加视图状态

    const callElectronAPI = () => {
      if (isElectron.value) {
        result.value = window.electronAPI.exampleMethod();
      } else {
        result.value = 'Electron API 不可用（当前运行在浏览器环境中）';
      }
    };

    return {
      result,
      isElectron,
      activeView, // 暴露视图状态
      callElectronAPI
    };
  }
};
</script>


<style scoped>
.app-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px;
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

.app-header {
  text-align: center;
  margin-bottom: 30px;
  padding-bottom: 20px;
  border-bottom: 1px solid #eee;
}

.app-header h1 {
  color: #2c3e50;
  font-size: 2.5rem;
  margin-bottom: 10px;
}

.subtitle {
  color: #7f8c8d;
  font-size: 1.1rem;
}

.app-content {
  display: grid;
  grid-template-columns: 1fr;
  gap: 30px;
}

.card {
  background: white;
  border-radius: 8px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  overflow: hidden;
  margin-bottom: 20px;
}

.card h2 {
  background: #3498db;
  color: white;
  padding: 15px 20px;
  margin: 0;
  font-size: 1.3rem;
}

.card-content {
  padding: 20px;
}

.primary-btn {
  background-color: #3498db;
  color: white;
  border: none;
  padding: 10px 20px;
  border-radius: 4px;
  font-size: 1rem;
  cursor: pointer;
  transition: all 0.3s ease;
  display: inline-flex;
  align-items: center;
  margin-top: 10px;
}

.primary-btn:hover {
  background-color: #2980b9;
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

.btn-icon {
  margin-right: 8px;
  font-size: 1.1rem;
}

.result-box {
  margin-top: 20px;
  padding: 15px;
  background-color: #f8f9fa;
  border-left: 4px solid #3498db;
  border-radius: 4px;
}

.result-box h3 {
  margin-top: 0;
  color: #2c3e50;
  font-size: 1rem;
}

@media (min-width: 768px) {
  .app-content {
    grid-template-columns: 1fr 1fr;
  }
  
  .electron-card {
    grid-column: span 2;
  }
}

/* 添加导航栏样式 */
.app-nav {
  display: flex;
  justify-content: center;
  margin: 20px 0;
  gap: 10px;
}

.nav-btn {
  padding: 8px 16px;
  background: none;
  border: 1px solid #3498db;
  color: #3498db;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.3s;
}

.nav-btn:hover {
  background-color: #f0f7ff;
}

.nav-btn.active {
  background-color: #3498db;
  color: white;
}

/* 响应式调整 */
@media (min-width: 768px) {
  .app-nav {
    gap: 20px;
  }
  
  .electron-card {
    grid-column: span 2;
  }
}
</style>